//chat_clnt.c
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define defaultAddr "127.0.0.1"
#define defaultPort 4000

int main(int argc,char* argv[]){
	char* address;
	unsigned short port;
	if(argc<2)
		address=strdup(defaultAddr);
	else
		address=strdup(argv[1]);
	if(argc<3)
		port=defaultPort;
	else
		port=(unsigned short)atoi(argv[2]);
	int csock;
	if((csock=socket(PF_INET,SOCK_STREAM,0))<0){
		perror("socket");
		exit(1);
	}
	struct sockaddr_in clnt_addr;
	memset(&clnt_addr,0,sizeof(clnt_addr));
	clnt_addr.sin_family=AF_INET;
	clnt_addr.sin_port=htons(port);
	clnt_addr.sin_addr.s_addr=inet_addr(address);
	if(connect(csock,(struct sockaddr*)&clnt_addr,sizeof(clnt_addr))<0){
		perror("connect");
		exit(1);
	}
	printf("접속에 성공했습니다.\n");
	close(csock);
	exit(0);
}
